package com.dbh.innerclass;

import com.dbh.Person;

import java.util.Comparator;

/**
 *  Comparators
 *
 *  Comparator接口在早期的Java版本中非常著名。Java 8 为这个接口添加了不同的默认方法。
 *
 * @author dongbanghui
 * @date 2018/08/16
 */
public class ComparatorsDemo {

    public static void main(String[] args) {
        Comparator<Person> comparator = (p1, p2) -> p1.firstName.compareTo(p2.firstName);

        Person p1 = new Person("John", "Doe");
        Person p2 = new Person("Alice", "Wonderland");

        comparator.compare(p1, p2);             // > 0
        comparator.reversed().compare(p1, p2);  // < 0
    }
}
